home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / read / RCS / read.c,v < prev   
Encoding:
Text File  |  1989-09-14  |  8.8 KB  |  424 lines

  1. head     1.6;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.6
  10. date     89.09.13.20.47.51;  author ouster;  state Exp;
  11. branches ;
  12. next     1.5;
  13.  
  14. 1.5
  15. date     88.03.10.16.10.28;  author brent;  state Exp;
  16. branches ;
  17. next     1.4;
  18.  
  19. 1.4
  20. date     88.03.02.13.10.32;  author brent;  state Exp;
  21. branches ;
  22. next     1.3;
  23.  
  24. 1.3
  25. date     88.03.02.08.42.39;  author brent;  state Exp;
  26. branches ;
  27. next     1.2;
  28.  
  29. 1.2
  30. date     88.02.06.17.30.47;  author nelson;  state Exp;
  31. branches ;
  32. next     1.1;
  33.  
  34. 1.1
  35. date     87.12.17.21.25.24;  author nelson;  state Exp;
  36. branches ;
  37. next     ;
  38.  
  39.  
  40. desc
  41. @@
  42.  
  43.  
  44. 1.6
  45. log
  46. @Switchover to version that can be ported to UNIX.
  47. @
  48. text
  49. @/* 
  50.  * read.c --
  51.  *
  52.  *    This program is a stand-alone benchmark to measure
  53.  *    the speed of reading a file.  It should be invoked
  54.  *    as follows:
  55.  *
  56.  *    read [count]
  57.  *
  58.  *    The program will read its standard input file count
  59.  *    times from start to finish, then print out the speed
  60.  *    of reading in bytes/sec.  If omitted, count defaults
  61.  *    to 1.
  62.  *
  63.  * Copyright 1989 Regents of the University of California.
  64.  * Permission to use, copy, modify, and distribute this
  65.  * software and its documentation for any purpose and without
  66.  * fee is hereby granted, provided that the above copyright
  67.  * notice appear in all copies.  The University of California
  68.  * makes no representations about the suitability of this
  69.  * software for any purpose.  It is provided "as is" without
  70.  * express or implied warranty.
  71.  */
  72.  
  73. #ifndef lint
  74. static char rcsid[] = "$Header: protoPub.c,v 1.3 87/01/04 17:28:56 andrew Exp $ SPRITE (Berkeley)";
  75. #endif not lint
  76.  
  77.  
  78. #include <stdio.h>
  79. #include <sys/time.h>
  80. #include <sys/resource.h>
  81.  
  82. static char buffer[16384];
  83.  
  84. main(argc, argv)
  85. int argc;
  86. char **argv;
  87. {
  88.     int cnt, total, repeats;
  89.     double rate, micros;
  90.     struct rusage begin ,end;
  91.     struct timeval start, stop;
  92.     struct timezone tz;
  93.  
  94.     if (argc == 1) {
  95.     repeats = 1;
  96.     } else {
  97.     repeats = atoi(argv[1]);
  98.     }
  99.     total = 0;
  100.  
  101. #ifdef GETRUSAGE
  102.     getrusage(RUSAGE_SELF, &begin);
  103. #else
  104.     gettimeofday(&start, (struct timezone *) NULL);
  105. #endif
  106.  
  107.     for ( ; repeats > 0; repeats--) {
  108.     lseek(0, 0, 0);
  109.     while (1) {
  110.         cnt = read(0, buffer, 16384);
  111.         total += cnt;
  112.         if (cnt < 16384) break;
  113.     }
  114.     }
  115. #ifdef GETRUSAGE
  116.     getrusage(RUSAGE_SELF, &end);
  117.     micros = (end.ru_utime.tv_sec + end.ru_stime.tv_sec
  118.         - begin.ru_utime.tv_sec - begin.ru_stime.tv_sec)*1000000
  119.         + (end.ru_utime.tv_usec - begin.ru_utime.tv_usec)
  120.         + (end.ru_stime.tv_usec - begin.ru_stime.tv_usec);
  121. #else
  122.     gettimeofday(&stop, (struct timezone *) NULL);
  123.     micros = 1000000*(stop.tv_sec - start.tv_sec)
  124.         + stop.tv_usec - start.tv_usec;
  125. #endif
  126.     rate = total/(micros/1000000.0);
  127.     printf("%d bytes read at %.0f bytes/sec.\n", total, rate);
  128. }
  129. @
  130.  
  131.  
  132. 1.5
  133. log
  134. @Updated error testing suite
  135. @
  136. text
  137. @d1 32
  138. a32 27
  139. #include "sprite.h"
  140. #include "time.h"
  141. #include "fs.h"
  142. #include "io.h"
  143. #include "option.h"
  144.  
  145. static char *buffer;
  146.  
  147. int    repeats = 1;
  148. int    blockSize = 16384;
  149. int    msToPause = -1;
  150. int    loops = -1;
  151. Boolean errorTest = FALSE;
  152.  
  153. Option optionArray[] = {
  154.     {OPT_INT, 'r', (Address) &repeats,
  155.      "\tNumber of times to repeat read (Default 1)."},
  156.     {OPT_INT, 'b', (Address) &blockSize, 
  157.      "\tBlock size to use for reading (Default 16384)."},
  158.     {OPT_INT, 'p', (Address)&msToPause,
  159.      "\tMilliseconds to pause between reads of each block. "},
  160.     {OPT_INT, 'l', (Address)&loops,
  161.      "\tNumber of times to loop between reads of each block. "},
  162.     {OPT_TRUE, 'e', (Address)&errorTest,
  163.      "\tTest error cases. "},
  164. };
  165. int numOptions = sizeof(optionArray) / sizeof(Option);
  166. d34 1
  167. a34 2
  168. int Handler();
  169. int gotSig = FALSE;
  170. d40 5
  171. a44 20
  172.     int         cnt, total;
  173.     double         rate, tmp;
  174.     Time         before, after;
  175.     Ioc_RepositionArgs    seek;
  176.     int            newOffset;
  177.     ReturnStatus    status;
  178.     Time        pauseTime;
  179.     Sig_Action        newAction, oldAction;
  180.     register    int    i;
  181.  
  182.     (void)Opt_Parse(&argc, argv, numOptions, optionArray);
  183.  
  184.     /*
  185.      * Set up signal handling, trap interrupts in order to test
  186.      * the GEN_INTERRUPTED_BY_SIGNAL return code.
  187.      */
  188.     newAction.action = SIG_HANDLE_ACTION;
  189.     newAction.handler = Handler;
  190.     newAction.sigHoldMask = 0;
  191.     Sig_SetAction(SIG_INTERRUPT, &newAction, &oldAction);
  192. d46 5
  193. a50 1
  194.     buffer = (char *)Mem_Alloc(blockSize);
  195. a51 79
  196.     if (msToPause > 0) {
  197.     pauseTime.seconds = 0;
  198.     pauseTime.microseconds = msToPause * 1000;
  199.     }
  200.  
  201.     if (errorTest) {
  202.     int numErrors = 0;
  203.     Io_Print("Read Error Tests\n"); Io_Flush(io_StdOut);
  204.  
  205.     Fs_Write(1, 3, "? ", &cnt);
  206.     status = Fs_Read(-2, 0, 0, &cnt);
  207.     if (status == SUCCESS) {
  208.         Io_Print("ERROR: Fs_Read(-2) worked!\n");
  209.         numErrors++;
  210.     } else {
  211.         Stat_PrintMsg(status, "Fs_Read(-2)");
  212.     }
  213.  
  214.     Fs_Write(1, 3, "? ", &cnt);
  215.     status = Fs_Read(0, 10, -1, &cnt);
  216.     if (status == SUCCESS) {
  217.         Io_Print("ERROR: Fs_Read{buffer = -1} worked!\n");
  218.         numErrors++;
  219.     } else {
  220.         Stat_PrintMsg(status, "Fs_Read{buffer = -1}");
  221.     }
  222.  
  223.     Fs_Write(1, 3, "? ", &cnt);
  224.     status = Fs_Read(0, -1, buffer, &cnt);
  225.     if (status == SUCCESS) {
  226.         Io_Print("ERROR: Fs_Read{count < 0} worked!\n");
  227.         numErrors++;
  228.     } else {
  229.         Stat_PrintMsg(status, "Fs_Read{count < 0}");
  230.     }
  231.  
  232.     /*
  233.      * This uses Fs_RawRead because the library routine Fs_Read
  234.      * dies on a bad amountReadPtr.
  235.      */
  236.     Fs_Write(1, 3, "? ", &cnt);
  237.     status = Fs_RawRead(0, 10, buffer, 0);
  238.     if (status == SUCCESS) {
  239.         Io_Print("ERROR: Fs_RawRead{&cnt = 0} worked!\n");
  240.         numErrors++;
  241.     } else {
  242.         Stat_PrintMsg(status, "Fs_RawRead{&cnt = 0}");
  243.     }
  244.  
  245.     {
  246.         int outFD2;
  247.         status = Fs_Open("/dev/null", FS_WRITE, 0,&outFD2);
  248.         if (status != SUCCESS) {
  249.         Io_PrintStream(io_StdErr, "Could not open %s for writing, status %x\n",
  250.                    "/dev/null", status);
  251.         } else {
  252.         status = Fs_Read(outFD2, 10, buffer, &cnt);
  253.         if (status == SUCCESS) {
  254.             Io_Print("ERROR: Fs_Read{writeonly stream} worked!\n");
  255.             numErrors++;
  256.         } else {
  257.             Stat_PrintMsg(status, "Fs_Read{writeonly stream}");
  258.         }
  259.         }
  260.     }
  261.  
  262.     {
  263.         char *newBuf = (char *)Mem_Alloc(100 * 1024);
  264.         Io_Print("Starting 100K read... "); Io_Flush(io_StdOut);
  265.         status = Fs_RawRead(0, 100 * 1024, newBuf, &cnt);
  266.         if (gotSig) {
  267.         Io_Print("Got Signal, "); Io_Flush(io_StdOut);
  268.         }
  269.         if (status == SUCCESS) {
  270.         Io_Print("Read %d bytes\n", cnt);
  271.         } else {
  272.         Stat_PrintMsg(status, "read");
  273.         }
  274.     }
  275. d53 12
  276. a64 8
  277.     Fs_Close(0);
  278.     Fs_Write(1, 3, "? ", &cnt);
  279.     status = Fs_Read(0, 10, buffer, &cnt);
  280.     if (status == SUCCESS) {
  281.         Io_Print("ERROR: Fs_Read{closed stream} worked!\n");
  282.         numErrors++;
  283.     } else {
  284.         Stat_PrintMsg(status, "Fs_Read{closed stream}");
  285. a65 28
  286.     if (numErrors) {
  287.         Io_Print("Read Test had %d errors\n", numErrors);
  288.     } else {
  289.         Io_Print("No errors\n");
  290.     }
  291.     Proc_Exit(numErrors);
  292.     } else {
  293.     Sys_GetTimeOfDay(&before, NULL, NULL);
  294.     for ( ; repeats > 0; repeats--) {
  295.         Ioc_Reposition(0, IOC_BASE_ZERO, 0, &newOffset);
  296.         while (1) {
  297.         if (msToPause > 0) {
  298.             Sync_WaitTime(pauseTime);
  299.         }
  300.         if (loops > 0) {
  301.             for (i = loops; i > 0; i --) {
  302.             }
  303.         }
  304.         status = Fs_Read(0, blockSize, buffer, &cnt);
  305.         total += cnt;
  306.         if (cnt < blockSize || status != SUCCESS) break;
  307.         }
  308.     }
  309.     Sys_GetTimeOfDay(&after, NULL, NULL);
  310.     rate = after.seconds - before.seconds;
  311.     rate += (after.microseconds - before.microseconds)*.000001;
  312.     rate = total/rate;
  313.     Io_Print("%d bytes read at %.0f bytes/sec.\n", total, rate);
  314. d67 13
  315. a79 6
  316. }
  317.  
  318. int
  319. Handler()
  320. {
  321.     gotSig = TRUE;
  322. @
  323.  
  324.  
  325. 1.4
  326. log
  327. @Updated it to exit with a status equal to the number of
  328. errors it found.
  329. @
  330. text
  331. @d108 15
  332. a122 7
  333.     Fs_Write(1, 3, "? ", &cnt);
  334.     status = Fs_Read(1, 10, buffer, &cnt);
  335.     if (status == SUCCESS) {
  336.         Io_Print("ERROR: Fs_Read{stdOut} worked!\n");
  337.         numErrors++;
  338.     } else {
  339.         Stat_PrintMsg(status, "Fs_Read{stdOut}");
  340. d147 5
  341. @
  342.  
  343.  
  344. 1.3
  345. log
  346. @Added error case testing.
  347. @
  348. text
  349. @d65 1
  350. d72 1
  351. d81 1
  352. d90 1
  353. d103 1
  354. d112 1
  355. d136 1
  356. d140 1
  357. a140 1
  358.  
  359. @
  360.  
  361.  
  362. 1.2
  363. log
  364. @Added looping and sleeping optoins.
  365. @
  366. text
  367. @d13 1
  368. d24 2
  369. d29 3
  370. d43 1
  371. d47 10
  372. d64 53
  373. a116 6
  374.     Sys_GetTimeOfDay(&before, NULL, NULL);
  375.     for ( ; repeats > 0; repeats--) {
  376.     Ioc_Reposition(0, IOC_BASE_ZERO, 0, &newOffset);
  377.     while (1) {
  378.         if (msToPause > 0) {
  379.         Sync_WaitTime(pauseTime);
  380. d118 23
  381. a140 2
  382.         if (loops > 0) {
  383.         for (i = loops; i > 0; i --) {
  384. d142 7
  385. a149 3
  386.         status = Fs_Read(0, blockSize, buffer, &cnt);
  387.         total += cnt;
  388.         if (cnt < blockSize || status != SUCCESS) break;
  389. d151 5
  390. d157 6
  391. a162 5
  392.     Sys_GetTimeOfDay(&after, NULL, NULL);
  393.     rate = after.seconds - before.seconds;
  394.     rate += (after.microseconds - before.microseconds)*.000001;
  395.     rate = total/rate;
  396.     Io_Print("%d bytes read at %.0f bytes/sec.\n", total, rate);
  397. @
  398.  
  399.  
  400. 1.1
  401. log
  402. @Initial revision
  403. @
  404. text
  405. @d11 2
  406. d19 4
  407. d30 8
  408. a37 6
  409.     int cnt, total;
  410.     double rate, tmp;
  411.     Time before, after;
  412.     Ioc_RepositionArgs seek;
  413.     int oldOffset;
  414.     ReturnStatus status;
  415. a40 2
  416.     seek.base = IOC_BASE_ZERO;
  417.     seek.offset = 0;
  418. d42 5
  419. d49 1
  420. a49 1
  421.     Ioc_Reposition(0, &seek, &oldOffset);
  422. d51 7
  423. @
  424.